﻿using Framework.Cache;
using Framework.Utility.Extensions;
using Framework.Utility.Helper;
using Hangfire;
using MonitorCode.Models;
using Support.Models;
using Support.Models.Entities;
using System.Collections.Generic;

namespace MonitorCode
{ 
    public class JobSeed
    {
        public static void CheckRedisSeed() 
        { 
            var monitorDatasList = CacheFactory.Cache.Get<List<Job_MonitorData>>(CacheKay.JobMonitorData) ?? new List<Job_MonitorData>();
            if (!monitorDatasList.Any())
            {
                CacheFactory.Cache.Set(CacheKay.JobMonitorData, JobMonitorDatas.ToJson());
            }

            var JobServersList  = CacheFactory.Cache.Get<List<Job_MonitorServer>>(CacheKay.JobMonitorServer) ?? new List<Job_MonitorServer>();
            if (!JobServersList.Any())
            {
                CacheFactory.Cache.Set(CacheKay.JobMonitorServer, JobServers.ToJson());
            }

            var JobDbLinkList = CacheFactory.Cache.Get<List<Job_DbLink>>(CacheKay.JobDbLink) ?? new List<Job_DbLink>();
            if (!JobDbLinkList.Any())
            {
                CacheFactory.Cache.Set(CacheKay.JobDbLink, JobDbLinkDatas.ToJson());
            }


            var JobReceiveEmailsList = CacheFactory.Cache.Get<List<Job_MonitorReceiveEmail>>(CacheKay.JobMonitorReceiveEmail) ?? new List<Job_MonitorReceiveEmail>();
            if (!JobReceiveEmailsList.Any())
            {
                CacheFactory.Cache.Set(CacheKay.JobMonitorReceiveEmail, JobReceiveEmails.ToJson());
            }
        } 

        public static List<Job_DbLink> JobDbLinkDatas = new List<Job_DbLink>
        {
            new Job_DbLink {
                Id=1,
                DBType = "Mysql",
                DBHostName = "127.0.0.1",
                Port=3306,
                DatabaseName =  "ldh" ,
                UserName="root",
                Password="123456",
                IsEnable = true,
                CreateBy="system",
                CreateTime=DateTime.Now,
            },
        };

        private static List<Job_MonitorServer> JobServers = new List<Job_MonitorServer>
        { 
            new Job_MonitorServer {
                Id=1,
                JobId = "05f20af7-8888-41a2-9c56-3905c52479f5", 
                ServerName = "appBaidu",
                GroupName="Support",
                ServerType="Site", 
                ServerUrl = "https://www.baidu.com", 
                CheckPath = "/", 
                CronExpression= "* * * * *",
                Status=JobFireStatus.No,
                IsEnable = true, 
                CheckTime = "", 
                CreateBy="system",
                CreateTime=DateTime.Now,
            }, 
        };

        private static List<Job_MonitorData> JobMonitorDatas = new List<Job_MonitorData>
        {
            new Job_MonitorData { 
                Id=1,
                DbLinkId=1,
                JobId = "05f20af7-6666-41a2-9c56-3905c52479f5",
                GroupName = "Support",
                ServerName = "模拟项目",
                CronExpression = "* * * * *",
                SqlText = "select * from biz_book",
                Status=JobFireStatus.No,
                IsEnable = true,
                CreateBy="system",
                CreateTime=DateTime.Now,
            },
        };

        private static List<Job_MonitorReceiveEmail> JobReceiveEmails = new List<Job_MonitorReceiveEmail>
        {
            new Job_MonitorReceiveEmail {
                Id=1,
                JobId = "05f20af7-8888-41a2-9c56-3905c52479f5",
                ReceiveEmail = "574427343@qq.com",
                CreateTime=DateTime.Now,
            },
            new Job_MonitorReceiveEmail {
                Id=1, 
                JobId = "05f20af7-6666-41a2-9c56-3905c52479f5",
                ReceiveEmail = "574427343@qq.com", 
                CreateTime=DateTime.Now,
            },
        };

        public static List<Job_MonitorDataRecord> JobMonitorDataRecords = new List<Job_MonitorDataRecord>
        {
            new Job_MonitorDataRecord { Id=1, JobId = "05f20af7-6666-41a2-9c56-3905c52479f5",  ResultCount = 8 ,ProcessDate = DateTime.Now.AddDays(-6).Date },
            new Job_MonitorDataRecord { Id=2,JobId = "05f20af7-6666-41a2-9c56-3905c52479f5",   ResultCount = 5 ,ProcessDate = DateTime.Now.AddDays(-5).Date},
            new Job_MonitorDataRecord { Id=3, JobId = "05f20af7-6666-41a2-9c56-3905c52479f5",  ResultCount = 5 ,ProcessDate = DateTime.Now.AddDays(-4).Date },
            new Job_MonitorDataRecord { Id=4,JobId = "05f20af7-6666-41a2-9c56-3905c52479f5",   ResultCount = 2 ,ProcessDate =DateTime.Now.AddDays(-3).Date },
            new Job_MonitorDataRecord { Id=5,JobId = "05f20af7-6666-41a2-9c56-3905c52479f5",   ResultCount = 0 ,ProcessDate =DateTime.Now.AddDays(-2).Date}, 
            new Job_MonitorDataRecord { Id=6,JobId = "05f20af7-6666-41a2-9c56-3905c52479f5",   ResultCount = 12 ,ProcessDate =DateTime.Now.AddDays(-1).Date },
            new Job_MonitorDataRecord { Id=7,JobId = "05f20af7-6666-41a2-9c56-3905c52479f5",   ResultCount = 15 ,ProcessDate =DateTime.Now.Date }, 
        };
         
    } 
}